﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DEMO.WCF_API.Services
{
    public class EXFaultContractSVC : DEMO.WCF_API.Contracts.IEXFaultContract
    {
        public DEMO.WCF_API.Contracts.EXMessageContract getEmployees(DEMO.WCF_API.Contracts.EXMessageContract oEXMessageContract)
        {
            try
            {
                if (oEXMessageContract == null || oEXMessageContract.Key == null || !oEXMessageContract.Key.Equals("Password@strong"))
                {
                    throw new System.ServiceModel.FaultException("Not Authorized Key", new System.ServiceModel.FaultCode("2"));
                }
                DEMO.DataLayer.DEMOEntities db = new DEMO.DataLayer.DEMOEntities();
                var Employees = (from p in db.DM_Employee
                                 join c in db.DM_EmployeeDetail on p.DME_ID equals c.DMED_DME_ID
                                 where p.DME_Flag == 1
                                 select new DEMO.WCF_API.Contracts.EXMessageContract
                                 {
                                     Key = oEXMessageContract.Key,
                                     oEmployee = new Contracts.Employee()
                                     {
                                         Email = p.DME_EmailID,
                                         EmployeeID = p.DME_ID,
                                         Name = c.DMED_FName + " " + c.DMED_LName
                                     },
                                     Password = p.DME_Password
                                 }).FirstOrDefault();
                return Employees;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        public DEMO.WCF_API.Contracts.ExFaultContractResult getEmployeesC(DEMO.WCF_API.Contracts.ExFaultContractSign oExFaultContractSign)
        {
            try
            {
                DEMO.WCF_API.Contracts.CustomException oCustomException = new Contracts.CustomException();
                if (oExFaultContractSign == null || oExFaultContractSign.Password == null || !oExFaultContractSign.Password.Equals("Password@strong"))
                {
                    oCustomException.cException = "Un-Authorize Access";
                    oCustomException.cExceptionDetail = "Password provided is incorrect.";
                    oCustomException.FaultCode = 2;

                    throw new System.ServiceModel.FaultException<DEMO.WCF_API.Contracts.CustomException>(oCustomException,"ss");
                }
                DEMO.DataLayer.DEMOEntities db = new DEMO.DataLayer.DEMOEntities();
                var Employees = (from p in db.DM_Employee
                                 join c in db.DM_EmployeeDetail on p.DME_ID equals c.DMED_DME_ID
                                 where p.DME_Flag == 1
                                 select new DEMO.WCF_API.Contracts.ExFaultContractResult
                                 {
                                     Email = p.DME_EmailID,
                                     EmployeeID = p.DME_ID,
                                     Name = c.DMED_FName + " " + c.DMED_LName,
                                     Password = p.DME_Password
                                 }).FirstOrDefault();
                return Employees;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
    }

}